#include <QtWidgets>
#include <QVector>
#include <QHostAddress>
#include <QTime>
#include <QProcess>
#include "client_jeu.hpp"
#include "cg_cartejoueur.h"
#include "cg_carteadverse.h"
#include "cg_tapis.h"
#include "cg_jeujoueur.h"
#include "cg_jeuadversaire.h"
#include "cg_partie.h"

class GraphicsView : public QGraphicsView
{
public:
    GraphicsView(QGraphicsScene *scene) : QGraphicsView(scene)
    {
        setHorizontalScrollBarPolicy ( Qt::ScrollBarAlwaysOff );
        setVerticalScrollBarPolicy ( Qt::ScrollBarAlwaysOff );
    }

protected:
    virtual void resizeEvent(QResizeEvent *)
    {
    }
};

int main(int argc, char **argv)
{
    qsrand(QTime::currentTime().msec());
    QApplication app(argc, argv);
    qreal largeur = QApplication::desktop()->availableGeometry().width();
    qreal hauteur = QApplication::desktop()->availableGeometry().height();

    ClientJeu clientJeu;
    clientJeu.connecter("pe46.eclair.ec-lyon.fr",45678);

    Cg_Partie *partie = new Cg_Partie(&clientJeu);
    QObject::connect(&clientJeu, SIGNAL(adversaires(std::vector<std::string>)), partie, SLOT(adversaires(std::vector<std::string>)));
    QObject::connect(&clientJeu, SIGNAL(numero_change(unsigned int)), partie, SLOT(numero_change(unsigned int)));
    QObject::connect(&clientJeu, SIGNAL(requete_refusee(Carte)), partie, SLOT(requete_refusee(Carte)));
    QObject::connect(&clientJeu, SIGNAL(pli_termine(unsigned int)), partie, SLOT(pli_termine(unsigned int)));
    QObject::connect(&clientJeu, SIGNAL(doit_priser(Option<Enchere>)), partie, SLOT(doit_priser(Option<Enchere>)));
    QObject::connect(&clientJeu, SIGNAL(enchere_acceptee(Enchere)), partie, SLOT(enchere_acceptee(Enchere)));
    QObject::connect(&clientJeu, SIGNAL(doit_appeler(std::vector<Carte>)), partie, SLOT(doit_appeler(std::vector<Carte>)));
    QObject::connect(&clientJeu, SIGNAL(appel_accepte(Carte)), partie, SLOT(appel_accepte(Carte)));
    QObject::connect(&clientJeu, SIGNAL(chien(Carte, Carte, Carte)), partie, SLOT(chien(Carte, Carte, Carte)));
    QObject::connect(&clientJeu, SIGNAL(doit_ecarter(std::vector<Carte>, std::vector<Carte>)), partie, SLOT(doit_ecarter(std::vector<Carte>, std::vector<Carte>)));
    QObject::connect(&clientJeu, SIGNAL(jeu_est(std::vector<Carte>)), partie, SLOT(jeu_est(std::vector<Carte>)));
    QObject::connect(&clientJeu, SIGNAL(partie_terminee(std::vector<int>)), partie, SLOT(partie_terminee(std::vector<int>)));
    QObject::connect(partie, SIGNAL(formuler_prise(Enchere::Prise)), &clientJeu, SLOT(formuler_prise(Enchere::Prise)));
    QObject::connect(partie, SIGNAL(formuler_appel(Carte)), &clientJeu, SLOT(formuler_appel(Carte)));
    QObject::connect(partie, SIGNAL(formuler_ecart(std::vector<Carte>)), &clientJeu, SLOT(formuler_ecart(std::vector<Carte>)));

    GraphicsView view(partie);
    view.setRenderHint(QPainter::Antialiasing);
    view.setViewportUpdateMode(QGraphicsView::BoundingRectViewportUpdate);
    view.setBackgroundBrush(QColor(32, 106, 6));
    view.setWindowTitle("Tarot Test");
    partie->addText(QString::number(largeur) + "x" + QString::number(hauteur));
    view.scale(largeur/1920,hauteur/1080);
    view.showFullScreen();

    return app.exec();
}
